Namespace Comm

    ''' <summary>
    ''' A base class that defines a stream to the BikiUSB Device
    ''' </summary>
    ''' <remarks></remarks>
    <ObfuscationAttribute(Exclude:=True, ApplyToMembers:=True)> _
    Public MustInherit Class BikiStream
        Inherits IO.Stream
        Implements IDisposable

        Private mCommuncationMutex As Threading.Mutex
        Private mUsbHandler As UsbCommunicationHandle

        Public Delegate Sub AsyncDataEvent(ByVal sender As Object, ByVal e As BikiStreamEventArgs)
        Public Event AsyncDataRecievedEvent As AsyncDataEvent

        ''' <summary>
        ''' Provides a base mutex for locking all communications
        ''' This passed mutex must be released upon a flush or close
        ''' operation
        ''' </summary>
        ''' <param name="CommunicationMutex"></param>
        ''' <remarks></remarks>
        Sub New(ByVal CommunicationMutex As Threading.Mutex, ByRef CommHandle As Comm.UsbCommunicationHandle)
            mCommuncationMutex = CommunicationMutex
            mUsbHandler = CommHandle
        End Sub

        Public Overrides Sub Close()
            mUsbHandler.ReleaseStream(Me)
            MyBase.Close()
        End Sub

        ''' <summary>
        ''' Specifies that a stream supports Streaming. Meaning data is recieved Asynchronously and will
        ''' be passed back via the AsyncData Event
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public MustOverride ReadOnly Property CanStream() As Boolean

    End Class

    ''' <summary>
    ''' Provides data returned from an Asynchronous dats stream
    ''' </summary>
    ''' <remarks></remarks>
    Public Class BikiStreamEventArgs
        Inherits System.EventArgs

        Private mData As Object

        Sub New(ByVal Data As Object)
            mData = Data
        End Sub

        Public ReadOnly Property Data() As Object
            Get
                Return mData
            End Get
        End Property
    End Class

End Namespace
